<template>
  <div>
    <el-input placeholder="请输入账号" v-model="user.name" />
    <el-input placeholder="请输入密码" v-model="user.pwd" type="password" />
    <el-button @click="loginFn">登录</el-button>
  </div>
</template>

<script>
import { LoginApi } from '@/request/api'
export default {
  data() {
    return {
      user: {}
    }
  },
  methods: {
    loginFn() {
      LoginApi({
        username: this.user.name,
        password: this.user.pwd
      }).then(res => {
        console.log(res)
        if (res.errno === 0) {
          localStorage.setItem('token', res.data.token)
          this.$store.commit("saveUserInfo", res.data.menu)
          this.$router.push('/home')
        }
      })
    }
  },

  created() {
    console.log("this.$store.state.userinfo", this.$store.state.userinfo)
  }

}
</script>

<style lang='less' scoped>
</style>